using System.Data.Entity.ModelConfiguration;
using HBCode.BusinessLogic.Entities;

namespace HBCode.BusinessLogic.Mapping
{
	public class ProductMap : EntityTypeConfiguration<Product>
	{
		public ProductMap()
		{
			// Primary Key
			this.HasKey(t => t.ProductID);

			// Properties
			this.Property(t => t.ProductName)
				.HasMaxLength(50);
				
			// Table & Column Mappings
			this.ToTable("Product");
			this.Property(t => t.ProductID).HasColumnName("ProductID");
			this.Property(t => t.ProductName).HasColumnName("ProductName");
			this.Property(t => t.Price).HasColumnName("Price");
			this.Property(t => t.CategoryID).HasColumnName("CategoryID");

			// Relationships
			this.HasOptional(t => t.Category)
				.WithMany(t => t.Products)
				.HasForeignKey(d => d.CategoryID);
				
		}
	}
}

